package org.xutils.db.log;

/**
 * Created by ZZH on 4/19/21.
 *
 * @Date: 4/19/21
 * @Email: zzh_hz@126.com
 * @QQ: 1299234582
 * @Author: zzh
 * @Description: 注入日志输出
 */
public class Log {
    private boolean isDebug = false;

    private boolean isDebugLogInsert = false;
    private boolean isDebugLogUpdate = false;
    private boolean isDebugLogDelete = false;
    private boolean isDebugLogQuery = false;
    private boolean isDebugLogCreate = false;
    private boolean isDebugLogAlter = false;

    private boolean isDebugLogDDL = false;


    public interface AndroidLogFactory {

        void d(String msg);

        void d(Throwable msg);

        void e(String msg);

        void e(Throwable msg);

        void i(String msg);

        void w(String msg);

        void w(Throwable msg);

        void a(String msg);
    }

    private Log() {
        //no instance
    }

    private static Log mLog;

    public static Log getInstance() {
        if (mLog == null) {
            synchronized (Log.class) {
                if (mLog == null) {
                    mLog = new Log();
                }

            }
        }
        return mLog;
    }

    public boolean isDebugLogDDL() {
        return isDebugLogDDL;
    }

    /**
     * 设置DROP 日志
     *
     * @param debugLogDDL true ，默认false
     * @return this
     */
    public Log setDebugLogDDL(boolean debugLogDDL) {
        isDebugLogDDL = debugLogDDL;
        return this;
    }

    public boolean isDebugLogAlter() {
        return isDebugLogAlter;
    }

    /**
     * alter 日志
     *
     * @param debugLogAlter true ，默认false
     * @return this
     */
    public Log setDebugLogAlter(boolean debugLogAlter) {
        isDebugLogAlter = debugLogAlter;
        return this;
    }

    public void setDebug(boolean debug) {
        isDebug = debug;
    }

    public boolean isDebug() {
        return isDebug;
    }

    /**
     * 插入语句是否打印log
     *
     * @return true 输出
     */
    public boolean isDebugLogInsert() {
        return isDebugLogInsert;
    }

    /**
     * 设置插入语句是否打印log
     *
     * @param debugLogInsert true 输出
     */
    public void setDebugLogInsert(boolean debugLogInsert) {
        isDebugLogInsert = debugLogInsert;
    }

    /**
     * 更新语句是否打印log
     *
     * @return true 输出
     */
    public boolean isDebugLogUpdate() {
        return isDebugLogUpdate;
    }

    /**
     * 更新语句是否打印log
     *
     * @param debugLogUpdate true 输出
     */
    public void setDebugLogUpdate(boolean debugLogUpdate) {
        isDebugLogUpdate = debugLogUpdate;
    }

    /**
     * 删除语句是否打印log
     *
     * @return true 输出
     */
    public boolean isDebugLogDelete() {
        return isDebugLogDelete;
    }

    /**
     * 删除语句是否打印log
     *
     * @param debugLogDelete true 输出
     */
    public void setDebugLogDelete(boolean debugLogDelete) {
        isDebugLogDelete = debugLogDelete;
    }

    /**
     * 查询语句是否打印log
     *
     * @return true 输出
     */
    public boolean isDebugLogQuery() {
        return isDebugLogQuery;
    }

    /**
     * 查询语句是否打印log
     *
     * @param debugLogQuery true 输出
     */
    public void setDebugLogQuery(boolean debugLogQuery) {
        isDebugLogQuery = debugLogQuery;
    }

    /**
     * 创建语句是否打印log
     *
     * @return true 输出
     */
    public boolean isDebugLogCreate() {
        return isDebugLogCreate;
    }

    /**
     * 创建语句是否打印log
     *
     * @param debugLogCreate true 输出
     */
    public void setDebugLogCreate(boolean debugLogCreate) {
        isDebugLogCreate = debugLogCreate;
    }

    private AndroidLogFactory mAndroidLogFactory;

    public void init(AndroidLogFactory androidLogFactory) {
        mAndroidLogFactory = androidLogFactory;
    }

    public final void d(String msg) {
        if (mAndroidLogFactory != null && isDebug()) {
            mAndroidLogFactory.d(msg);
        }
    }

    public final void d(Throwable msg) {
        if (mAndroidLogFactory != null && isDebug()) {
            mAndroidLogFactory.d(msg);
        }
    }

    public final void e(String msg) {
        if (mAndroidLogFactory != null && isDebug()) {
            mAndroidLogFactory.e(msg);
        }
    }

    public final void e(Throwable msg) {
        if (mAndroidLogFactory != null && isDebug()) {
            mAndroidLogFactory.e(msg);
        }
    }

    public final void w(String msg) {
        if (mAndroidLogFactory != null && isDebug()) {
            mAndroidLogFactory.w(msg);
        }
    }

    public final void w(Throwable msg) {
        if (mAndroidLogFactory != null && isDebug()) {
            mAndroidLogFactory.w(msg);
        }
    }

    /*******************/
    public final void dx(String msg) {
        if (mAndroidLogFactory != null) {
            mAndroidLogFactory.d(msg);
        }
    }

    public final void dx(Throwable msg) {
        if (mAndroidLogFactory != null) {
            mAndroidLogFactory.d(msg);
        }
    }

    public final void ex(String msg) {
        if (mAndroidLogFactory != null) {
            mAndroidLogFactory.e(msg);
        }
    }

    public final void ex(Throwable msg) {
        if (mAndroidLogFactory != null) {
            mAndroidLogFactory.e(msg);
        }
    }

    public final void wx(String msg) {
        if (mAndroidLogFactory != null) {
            mAndroidLogFactory.w(msg);
        }
    }

    public final void wx(Throwable msg) {
        if (mAndroidLogFactory != null) {
            mAndroidLogFactory.w(msg);
        }
    }

}
